package io.renren.modules.ccs.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.ccs.entity.HistoryEntity;
import io.renren.modules.ccs.service.HistoryService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author SongR
 * @email 348329560@qq.com
 * @date 2018-07-25 16:03:24
 */
@RestController
@RequestMapping("ccs/history")
public class HistoryController {
    @Autowired
    private HistoryService historyService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("ccs:history:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = historyService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{historyId}")
    @RequiresPermissions("ccs:history:info")
    public R info(@PathVariable("historyId") Long historyId){
        HistoryEntity history = historyService.selectById(historyId);

        return R.ok().put("history", history);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("ccs:history:save")
    public R save(@RequestBody HistoryEntity history){
        historyService.insert(history);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("ccs:history:update")
    public R update(@RequestBody HistoryEntity history){
        ValidatorUtils.validateEntity(history);
        historyService.updateAllColumnById(history);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("ccs:history:delete")
    public R delete(@RequestBody Long[] historyIds){
        historyService.deleteBatchIds(Arrays.asList(historyIds));

        return R.ok();
    }

}
